<%@page import="com.enterprise.daoImpl.NewsDaoImpl"%>
<%@page import="com.enterprise.daoImpl.NodeDaoImpl,com.enterprise.domain.*"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="Inc/Head.jsp" %>
<%
	int id=Integer.parseInt(request.getParameter("ID"));
	News n=new NewsDaoImpl().getNews(id);
	

 %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%!
	NodeDaoImpl nodeDaoImpl=new NodeDaoImpl();
	List<Node> list=nodeDaoImpl.getNodes(-1);
	String[][] nameString=new String[list.size()][];
	int[][] nameid=new int[list.size()][];
	%>
	<%
	if(list.size()>0)
	for(int i=0;i<list.size();i++)
	{
	 	List<Node> childrenNode=nodeDaoImpl.getNodes(list.get(i).getId());
	 	nameString[i]=new String[childrenNode.size()];
	 	nameid[i]=new int[childrenNode.size()];
	 	if(childrenNode!=null&&childrenNode.size()>0)
	 	for(int j=0;j<childrenNode.size();j++){
	 	
	 		nameString[i][j]=new String(childrenNode.get(j).getClassName());
	 		nameid[i][j]=new Integer(childrenNode.get(j).getId());
	 	}
		
	}
	
	for(int i=0;i<nameString.length;i++){
		for(int j=0;j<nameString[i].length;j++)
		System.out.print(nameString[i][j]);
		System.out.println("");
		}
 %>

<script language = "JavaScript">


function getChange(){
	var bigClass=document.getElementById("bigClassName");
	var secondClass=document.getElementById("secondClassName");
	secondClass.options.length=0;
	var index=bigClass.selectedIndex;
	<%-- 
	<%!int i=0;%>
	for(var i=0;i<<%=nameString.length%>;i++)
	{
	<% i++;%>
		if(index==i){
		for(var j=0;j<<%=nameString[i].length%>;j++)
			secondClass.options.add(new Option("<%=nameString[i]%>"))
		}
	} --%>
	<%
		for(int i=0;i<nameString.length;i++){
			%>
			if(index==<%=i%>){
				<%for(int j=0;j<nameString[i].length;j++){%>
				secondClass.options.add(new Option('<%=nameString[i][j]%>','<%=nameid[i][j]%>'))
				
				<%}%>
			}
			
			<%
		}
	%>


}

  

function AddItem(strFileName){
  document.myform.IncludePic.checked=true;
  document.myform.DefaultPicUrl.value=strFileName;
  document.myform.DefaultPicList.options[document.myform.DefaultPicList.length]=new Option(strFileName,strFileName);
  document.myform.DefaultPicList.selectedIndex+=1;
  if(document.myform.UploadFiles.value==''){
	document.myform.UploadFiles.value=strFileName;
  }
  else{
    document.myform.UploadFiles.value=document.myform.UploadFiles.value+"|"+strFileName;
  }
}

function CheckForm()
{
    if (editor.EditMode.checked==true)
	  document.myform.Content.value=editor.HtmlEdit.document.body.innerText;
    else
	  document.myform.Content.value=editor.HtmlEdit.document.body.innerHTML; 

	if (document.myform.title.value.length == 0) {
		alert("新闻标题没有填写.");
		document.myform.title.focus();
		return false;
	}
	if (document.myform.BigClassName.value.length == 0) {
		alert("新闻大类没有选");
		document.myform.BigClassName.focus();
		return false;
	}
	
		if (document.myform.user.value.length == 0) {
		alert("新闻发布人没有填写");
		document.myform.user.focus();
		return false;
	}
	return true;
}
</script>


<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
  <tr> 
    <td align="center" valign="top">
	<table width="95%" border="0" cellpadding="2" cellspacing="1" class="table_southidc">
        <form method="POST" name="myform" onSubmit="return CheckForm();" action="<%=basePath%>news-update.action" target="_self">
          <tr> 
            <td class="back_southidc" height="30" colspan="2" align="center">增加新闻</td>
          </tr>
          <tr bgcolor="#ECF5FF"> 
            <td width="119" height="25"><font color="#FF0000">*</font>新闻标题：</td>
            <td width="476"> <input name="news.title" type="text" class="input" size="50" maxlength="200" value="<%=n.getTitle()%>"></td>
          </tr>
          <tr bgcolor="#ECF5FF"> 
            <td height="25"><font color="#FF0000">*</font>新闻类别：</td>
            <td> 
		<select name="news.bigClassName" onChange="getChange();" size="1" id="bigClassName">
		<%if(list!=null&&list.size()>0)
			for(Node node:list){
			%>
		
		 
                <option selected value="<%=node.getId()%>"><%=node.getClassName()%></option>
                
			<% }%>
               
              </select> <select name="news.secondClassName" id="secondClassName">
                <option value="" selected>不指定小类</option>
               
               
                
                

              </select></td>
          </tr>
          <tr bgcolor="#ECF5FF"> 
            <td height="25" valign="top"><font color="#FF0000">*</font>新闻内容：</td>
                   <td height="300"> 
                      <ckfinder:setupCKEditor editor="content" basePath="ckfinder/" />   
		     <ckeditor:editor basePath="ckeditor/"    
		            editor="news.content" value="<%=n.getContent()%>"  />   
		     
                    </td>
          </tr>
          <!-- <tr bgcolor="#ECF5FF"> 
            <td height="25">首页图片： 
              <input name="IncludePic" type="hidden" id="IncludePic" value="yes"></td>
            <td><input name="DefaultPicUrl" type="text" id="DefaultPicUrl" size="40" maxlength="120"> 
              <br>
              首页的图片,直接从上传图片中选择： 
            
            
              <select name="DefaultPicList" id="select" onChange="DefaultPicUrl.value=this.value;">
                <option selected>不指定首页图片</option>
              </select> <input name="UploadFiles" type="hidden" id="UploadFiles"> 
            </td>
          </tr> -->
           <tr bgcolor="#ECF5FF"> 
            <td height="25"><font color="#FF0000">*</font>发布人：</td>
            <td> <input name="news.publisher" type="text" class="input" value="<%=session.getAttribute("loginUsername")%>" size="30"></td>
            <input name="news.viewCounts" value="0" type="hidden">
            <input name="news.id" value="<%=n.getId() %>" type="hidden">
          </tr> 
          <tr bgcolor="#ECF5FF"> 
            <td height="25">首页图片新闻：</td>
            <td> <input type="radio" name="ok" value="Yes">
              是 
              <input name="ok" type="radio" value="No" checked>
              否 　<font color="#FF0000">（设为首页图片新闻，选择此项时请注意文章中是否添加有图片！）</font></td>
          </tr>
          <tr> 
            <td height="30" align="center" bgcolor="#ECF5FF"><div align="left">录入时间：</div></td>
            <td height="30" align="center" bgcolor="#ECF5FF"><div align="left"> 
                <input name="news.addDate" type="text" id="addDate" value="<%=new SimpleDateFormat("yyyy-MM-dd").format(n.getAddDate())%>" maxlength="50">
              </div></td>
          </tr>
          <tr>
            <td height="30" colspan="2" align="center" bgcolor="#ECF5FF"> <input type="submit" name="Submit" value="提交" class="input">
              　 
              <input type="reset" name="Submit" value="重置" class="input"> </td>
          </tr>
        </form>
      </table></td>
  </tr>
</table>
<%@ include file="Inc/Foot.jsp"%>